Sortwith Method

Sorts one or more additional arrays in the same order as the base array. The sort is in ascending order.

Syntax



array.Sortwith(array1[,...arrayN])


Notes

The base array used with the Sortwith method works with Integer, String, Single, and Double arrays only. It accepts only one-dimensional arrays.

Sortwith is ideal for sorting all the columns of a data table by one of its columns. For example, if you have a set of three arrays that store Names, Addresses, and Phone numbers of a group of people, you can sort the data table by Name by specifying the Names array as the base array and pass the Address and Phone number arrays as the parameters.


Examples

This example sorts the columns of the data table by the values in the aNames array.

Dim aNames(), aAddresses(),aPhones() as String
aNames= Array("Mozart","Bing","Jackson","Flintstone")
aAddresses= Array("34 Pickwick","3424 Kenwood","432 Marlboro","1 Hardrock")
aPhones= Array("234-3700","697-5300","753-2500","None")

aNames.Sortwith(aAddresses,aPhones)

//display the sorted arrays in a Listbox to verify the sort
For i as Integer=0 to Ubound(aNames)
 ListBox1.addrow aNames(i)
 ListBox1.cell(i+1,1)=aAddresses(i)
 ListBox1.cell(i+1,2)=aPhones(i)
Next

See Also

Dim statement; Array, Join, Split, Ubound functions; Append, IndexOf, Insert, Pop, Redim, Remove, Shuffle, Sort methods; ParamArray keyword.